//index.js
//获取应用实例
const app = getApp();
var common=require ('../../utils/common.js');
Page({
  data: {
    bannerList:[],
    articleList:[],
    page:0
  },
  
  onLoad: function () {    
    
    var that=this;    
    common.getData({type:0},that);
    
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      var that = this;
      var data = { type:0 };

      common.getData(data, that);
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (e) {
      wx.showLoading({
          title: '加载中...',
      })
      var that = this;
      
      var page = that.data.page;
      var start = page * 10 + 10
      wx.request({
          url: `${app.apiHost}article/ajaxarticle`,   //es6写法
          data: { start: start, type:0 },
          success: function (res) {
              var data = res.data;
              if (data.code == 200) {
                  var obj = that.data.articleList.concat(data.content.articleList);

                  that.setData({ articleList: obj, page: ++page });
              } else if (data.code == 2) {
                  //setTimeout(() => wx.hideLoading(), 500);
                  setTimeout(() => {
                      wx.showToast({
                          title: '没有更多了',
                          icon: 'none'
                      })
                  }, 600)

              }

          },
          complete: function () {
              setTimeout(() => wx.hideLoading(), 500);
          }
      })
  },
})
